import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class AppList extends HttpServlet
{
    private static final long serialVersionUID = -5393027191231118185L;
    
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    {
        try
        {
            PrintWriter out = response.getWriter();
            out.println("<html><head><style type=\"text/css\">table{color:#565;font:16px arial;text-align:left;}tbody td,tbody th{background-color:#dfc;border-bottom:2px solid #b3de94;border-top:3px solid #fff;padding:9px;}thead th{font-size:14px;font-weight:bold;line-height:19px;padding:0 8px 2px;text-align:center;}tbody tr.even th,tbody tr.even td{background-color:#cea;border-bottom:2px solid #67bd2a;background-color:#66CDAA;border-bottom:2px solid #228B22;}div.head {margin-left:5cm;margin-right:5cm;background-color: #D2B48C;font-size:250%;padding-left:22%;height:80px;}body {background-color: #FFFAFA}div.no1{margin-left:5cm;margin-right:5cm;padding-left:12%;font-family:Arial,Verdana,Sans-serif;font-weight:bold;background-color: #FAF0E6; height: 500px;padding-top:0.5cm;}</style><title>Registered Applications</title></head><body>");
            
            out.println("<div class= \"head\"><p style=\"color: #ffffff\"> <font face=\"comic sans ms\" >Registered Applications</p></div><div class=\"no1\"><table class=\"table\"><thead><col /><col /><col /><col /><col /><col/><tr><th>File Name</th><th>Start Command</th><th>Port</th></tr></thead><tbody>");
            
           
            for (Application app : Metadata.getInstance().getApps())
                out.println("<tr><td>" + app.filename + "</td><td>" + app.command + "</td><td>" + app.port + "</td></tr>");
            
            out.println("</tbody></table>");
            out.println("<a href=\"/\">Back to home</a>");
            out.println("</div>"); 
            
            out.println("</body></html>");
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }

}
